-
Notifications
You must be signed in to change notification settings - Fork 397
feat(context): de-duplicate hook names within configs #1216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1216 +/- ##
==========================================
- Coverage 14.04% 14.03% -0.01%
==========================================
Files 2366 2366
Lines 205444 205443 -1
Branches 185808 185807 -1
==========================================
- Hits 28845 28841 -4
- Misses 175175 175178 +3
Partials 1424 1424 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1c0ed4e to
7e29f10
Compare
crates/q_cli/src/cli/chat/context.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like having a lot of extra logic for validating and creating new hook names when this could also be solved by just changing the structure used when saving hooks. We have that ContextConfig is already saved per profile, so instead of saving hooks as a list of hooks, why not instead have it be:
ContextConfig {
paths: ...,
hooks: HookConfig {
conversation_start: { [key: string]: Hook },
per_prompt: { [key: string]: Hook },
}
}
This way we could also avoid having to create randomly generated id's for hook names. I feel it's simpler for us and the user to just present an error to the user stating a hook with that name already exists instead of this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContextConfig { paths: ..., hooks: HookConfig { conversation_start: { [key: string]: Hook }, per_prompt: { [key: string]: Hook }, } }
This won't work either. Hook names have to be unique across conversation_start AND per_prompt, otherwise this is ambiguous: /context hooks rm my_hook. my_hook could be in either of the categories.
This way we could also avoid having to create randomly generated id's for hook names. I feel it's simpler for us and the user to just present an error to the user stating a hook with that name already exists instead of this approach.
It's not random, and I would argue its easier for the user because there is never a failure point for them. Their hook always gets added. Also, there is a lack of any config validation happening that we desperately need, whether right now or later (currently if there is an issue with the JSON then the context manager just doesn't load without any warning to the user).
However, the automatic renaming may be confusing, and maybe this issue is a just a symptom of the structure of the config. Maybe we can resolve this by just changing the schema to not have these separations. Thoughts?
context.json
{
paths: [ ... ],
hooks: {
my_hook : { // the name, which is now unique amongst all hooks in the config file
// category
"when": "conversation_start" | "per_prompt", // open to a different name, could be "on" as well
... normal hook data
}
...
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and I would argue its easier for the user because there is never a failure point for them. Their hook always gets added. Also, there is a lack of any config validation happening that we desperately need, whether right now or later
Definitely true about handling validation and serialization errors - although, the random naming is still just strange to me because hooks should probably have some more semantic meaning to their name instead of just having the user get away with hook_1, hook_2, hook_3 etc. I'd like to hear others thoughts on this hook naming part before going with this approach.
Maybe we can resolve this by just changing the schema to not have these separations. Thoughts?
I'd prefer this! Saves having to have hook name as a validation check in any validation logic we might have.
Updated the schema to be:
```
{
"hooks": {
"my_hook_name": {
...hook data
"trigger": "conversation_start" | "per_prompt",
}
}
}
```
So that we do not have to worry about duplicate name hooks or generating an ID for a hook. Whether the user adds a new hook via commands or editing the JSON file, the invariant holds true.
Additionally:
- Separate execution caches for profile/global, so that we don't have to worry about name overlappying
- also allows us to clear hook cache when switch profile
- Rename CLI arg `--type` to `--trigger` for `/context hooks add ...`
7e29f10 to
80dec01
Compare
Updated the schema to be:
```
{
"hooks": {
"my_hook_name": {
...hook data
"trigger": "conversation_start" | "per_prompt",
}
}
}
```
So that we do not have to worry about duplicate name hooks or generating an ID for a hook. Whether the user adds a new hook via commands or editing the JSON file, the invariant holds true.
Additionally:
- Separate execution caches for profile/global, so that we don't have to worry about name overlappying
- also allows us to clear hook cache when switch profile
- Rename CLI arg `--type` to `--trigger` for `/context hooks add ...`
Follow up to #1176 (comment)
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.